package com.zq.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zq.pojo.MsgInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class PubliserService {

    private static final Logger logger=LoggerFactory.getLogger(PubliserService.class);

    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;


    public  void sender(){
        try {
            MsgInfo msgInfo = new MsgInfo();
            msgInfo.setId(1);
            msgInfo.setCode("我是消息");
            msgInfo.setModel("auto");
            String s = objectMapper.writeValueAsString(msgInfo);
            rabbitTemplate.convertAndSend("autoEx", "autoQueue", s);

            System.out.println("info is succ");
           logger.info("info is succ");


        }catch (Exception e){
            System.out.println("info is false");
            logger.info("info is false");
            e.printStackTrace();
        }






    }

}
